package com.leetcode;

import java.util.HashMap;

public class L0001 {
    public static void main(String[] args) {
        int[] nums={2,7,11,15};
        int target=9;
        int[] ints = twoSum(nums, target);
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }

    public static int[] twoSum(int[] nums, int target) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int[] arr=new int[2];
        for (int i=0;i<nums.length;i++){
             if (!map.containsKey(target-nums[i])){
                 map.put(nums[i],i);
             }else{
                 arr[0]= map.get(target-nums[i]);
                 arr[1]=i;
                 break;
             }
        }
        return arr;
    }
}
